
$(function() {
	
	var count = 1;
    var num = 1
    $('#form1').append(getStr());
    // 默认选中是
    $("input[value='1']").attr('checked','true');
    $('.more').click(function (e) {
      num ++
      $('#form'+ count).after("<form id='form"+num+"' class='form'><div class='box'><i id='delete"+num+"' class='icon glyphicon glyphicon-remove'></i></div></form>")
      $('#form'+ num+ ' .box').append(getStr)
      // 默认选中是
      $("input[value='1']").attr('checked','true');
      $('#delete'+ num).click(function (e) {
        $('#form'+ num).remove()
        num--
        count = num
      })
      count = num
    })

    $('#submit').click(function (e) {
      var companyName = $("input[name='companyName']")
      if(companyName.val() === ''){
        companyName.parent('.info-group').addClass('has-error')
        companyName.next('.error').html('请输入企业名称')
        return;
      }else{
        companyName.parent('.info-group').removeClass('has-error')
        companyName.next('.error').html('')
      }
      var personalName = $("input[name='personalName']")
      if(personalName.val() === ''){
        personalName.parent('.info-group').addClass('has-error')
        personalName.next('.error').html('请填写姓名')
        return;
      }else{
        personalName.parent('.info-group').removeClass('has-error')
        personalName.next('.error').html('')
      }
      var phone = $("input[name='phone']")
      if(phone.val() === ''){
        phone.parent('.info-group').addClass('has-error')
        phone.next('.error').html('请填写电话')
        return;
      }else{
        phone.parent('.info-group').removeClass('has-error')
        phone.next('.error').html('')
      }
      var tradeName = $("input[name='tradeName']")
      tradeName.each(function( i,ele){
        console.log($(ele).val(),"===")
        if($(ele).val() === ''){
          $(ele).parent('.form-inline').addClass('has-error')
          $(ele).next('.trade-name-error').html('请填写厂商名称')
          return;
        }else{
          $(ele).parent('.form-inline').removeClass('has-error')
          $(ele).next('.trade-name-error').html('')
        }
      })

      var formStr = ''
      /*
		 * for(var i=1;i<=count;i++) { formStr += '#form'+ i +','
		 * console.log($('#form'+ i)) }
		 */
      var obj = {};
      
      for(var i=1;i<=count;i++) {
      	obj['key'+i] = $('#form'+ i).serialize();  
      }
      obj['key'] = $('#form').serialize();  
      
      // 获取所有表单的id
      //formStr += '#form'
      //var data = $(formStr).serialize()
	 
	 $.ajax({
		type : "post",
		url :  "questionnaire/questionnaireOper",
		data : obj,
		dataType : "json",
		success : function(data) {
			if (data.flag) {
			   alert("提交成功！");
			}
		}
	});
    })
});


function getStr(){
	var str = `<div class="question_box">
        <div class="form-group">
          <label class="title">1.信安系统建设厂商名称？</label>
          <div class="form-inline">
            <input type="text" class="form-control trade-name" name="tradeName" required>
            <label class="trade-name-error"></label>
          </div>
        </div>
        <div class="form-group">
          <label class="title">2.厂商服务质量是否满足要求？</label>
          <div class="radio-box">
            <input type="radio" name="question2" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question2" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">3.系统故障是否能及时修复？</label>
          <div class="radio-box">
            <input type="radio" name="question3" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question3" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">4.系统是否能满足系统升级、改造、扩容等业务需求？</label>
          <div class="radio-box">
            <input type="radio" name="question4" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question4" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">5.系统功能是否符合标准要求？</label>
          <div class="radio-box">
            <input type="radio" name="question5" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question5" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">6.系统功能界面设计和可操作性是否合理？</label>
          <div class="radio-box">
            <input type="radio" name="question6" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question6" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">7.系统是否具备身份认证和权限管理功能？</label>
          <div class="radio-box">
            <input type="radio" name="question7" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question7" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">8.系统是否记录操作日志？</label>
          <div class="radio-box">
            <input type="radio" name="question8" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question8" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">9.系统性能是否满足标准要求？</label>
          <div class="radio-box">
            <input type="radio" name="question9" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question9" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">10.系统稳定性是否满足安全管理要求？</label>
          <div class="radio-box">
            <input type="radio" name="question10" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question10" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">11.系统是否具备可扩展能力？</label>
          <div class="radio-box">
            <input type="radio" name="question11" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question11" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">12.系统处理能力能否全覆盖机房出口带宽？</label>
          <div class="radio-box">
            <input type="radio" name="question12" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question12" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">13.系统能否具备数据安全自动核验功能？</label>
          <div class="radio-box">
            <input type="radio" name="question13" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question13" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">14.系统是否存在数据泄露风险？</label>
          <div class="radio-box">
            <input type="radio" name="question14" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question14" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">15.厂商是否私自使用系统数据用作其他用途？</label>
          <div class="radio-box">
            <input type="radio" name="question15" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question15" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">16.是否与厂商签订安全保密协议？</label>
          <div class="radio-box">
            <input type="radio" name="question16" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question16" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">17.系统是否满足三级安全防护要求？</label>
          <div class="radio-box">
            <input type="radio" name="question17" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question17" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">18.系统是否发生过网络安全事件？</label>
          <div class="radio-box">
            <input type="radio" name="question18" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question18" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">19.厂商是否定期进行网络安全检测？</label>
          <div class="radio-box">
            <input type="radio" name="question19" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question19" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">20.厂商是否驻派专门运维人员或区域运维人员？</label>
          <div class="radio-box">
            <input type="radio" name="question20" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question20" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">21.厂商运维人员是否熟悉信安系统相关专业知识？</label>
          <div class="radio-box">
            <input type="radio" name="question21" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question21" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">22.厂商对系统运行维护是否满足要求？</label>
          <div class="radio-box">
            <input type="radio" name="question22" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question22" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">23.是否对系统进行7*24小时监控？</label>
          <div class="radio-box">
            <input type="radio" name="question23" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question23" value="0">
            <span>否</span>
          </div>
        </div>
        <div class="form-group">
          <label class="title">24.其他意见或建议</label>
          <div class="radio-box">
            <input type="radio" name="question24" value="1">
            <span>是</span>
          </div>
          <div class="radio-box">
            <input type="radio" name="question24" value="0">
            <span>否</span>
          </div>
        </div>         
      </div>`
	return str;
}